package com.gome.boot.config.elasticsearch.cluster.selector;

import com.gome.boot.config.elasticsearch.cluster.ClusterClient;
import com.gome.boot.config.elasticsearch.cluster.MultiClusterSelector;

import java.util.List;

/**
 * ES多集群选择器基础实现.
 *
 * @author baoxiufeng
 */
public abstract class AbstractSelectCluster implements MultiClusterSelector {

    /**
     * 处理无可用集群或仅有一个可用集群的选择.
     *
     * @param clients 集群列表
     * @return 集群客户端工具
     */
    protected ClusterClient select(List<ClusterClient> clients) {
        int size = clients.size();
        switch (size) {
            case 0: throw new RuntimeException("Have not available cluster.");
            case 1: return clients.get(0);
            default: return null;
        }
    }
}
